package com.itheima.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.dao.BookDao;
import com.itheima.domain.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author tongchen
 * @create 2022-12-17 15:56
 */
@Service
public class BookSreviceImpl implements BookService{
    @Autowired
   private BookDao bookDao;
    @Override
    public boolean save(Book book) {
        return bookDao.insert(book)>0;
    }

    @Override
    public boolean deleteById(Integer id) {
        return bookDao.deleteById(id)>0;
    }

    @Override
    public boolean update(Book book) {
        return bookDao.updateById(book)>0;
    }

    @Override
    public Book selectById(Integer id) {
        Book book = bookDao.selectById(id);
        return book;


    }

    @Override
    public List<Book> selectAll() {
        List<Book> books = bookDao.selectList(null);
        return books;
    }

    @Override
    public IPage<Book> selectByPage(Integer column,Integer num) {
        IPage<Book> iPage=new Page<>(column,num);
        bookDao.selectPage(iPage,null);
        return iPage;
    }
}
